package io.renren.modules.noc.service.impl;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Random;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;

import io.renren.modules.noc.dao.NocBeerTicketBusinessDao;
import io.renren.modules.noc.entity.NocBeerTicketBusinessEntity;
import io.renren.modules.noc.service.NocBeerTicketBusinessService;


@Service("nocBeerTicketBusinessService")
public class NocBeerTicketBusinessServiceImpl extends ServiceImpl<NocBeerTicketBusinessDao, NocBeerTicketBusinessEntity> implements NocBeerTicketBusinessService {

    @Autowired
    private NocBeerTicketBusinessDao nocBeerTicketBusinessDao;

    @Value("${ercode.beerPre}")
    private String _beerPre;
    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<NocBeerTicketBusinessEntity> page = this.page(
                new Query<NocBeerTicketBusinessEntity>().getPage(params),
                new QueryWrapper<NocBeerTicketBusinessEntity>()
        );

        return new PageUtils(page);
    }

    public Integer ifExist(Map<String,Object> map){
        return nocBeerTicketBusinessDao.ifExist(map);
    }

    @Override
    public String getNextErCode(String pre){
        return nocBeerTicketBusinessDao.getNextErCode(pre);
    }
    @Override
    public String getNextErCodeBeer(){
        Random r = new Random();
        int n2 = r.nextInt(999999);
        String s = String.valueOf(n2);
        if(s.length()<6){
            for(int j=0;j<6-s.length();j++){
                s="0"+s;
            }
        }
        Map<String,Object> map = new HashMap<>();
        map.put("ercode","_beerPre"+s);
        Integer count = nocBeerTicketBusinessDao.getCount(map);
        while(count!=0){
            n2= r.nextInt(999999);
            s = String.valueOf(n2);
            if(s.length()<6){
                for(int j=0;j<6-s.length();j++){
                    s="0"+s;
                }
            }
            Map<String,Object> map1 = new HashMap<>();
            map1.put("ercode","_beerPre"+s);
            count = nocBeerTicketBusinessDao.getCount(map1);

        }
        return _beerPre+s;

    }

    @Override
    public List<NocBeerTicketBusinessEntity> getNocBeerTicketBusinessEntity(){
        return nocBeerTicketBusinessDao.getNocBeerTicketBusinessEntity();
    }

    @Override
    public String getAllCount (Map<String,Object> map){
        return nocBeerTicketBusinessDao.getAllCount(map);
    }



    @Override
    public String getIsSign (Map<String,Object> map) {return nocBeerTicketBusinessDao.getIsSignById(map);}
    @Override
    public Map<String,Object> getIsSignByCode(Map<String,Object> map){
        return nocBeerTicketBusinessDao.getIsSign(map);
    }
}
